const fs = require("fs");
window.addEventListener("DOMContentLoaded", () => {
  const DROP = document.getElementById("drop");
  const READ = document.getElementById("read");
  DROP.addEventListener("drop", e => {
    e.preventDefault();
    e.stopPropagation();
    try {
      for (let file of e.dataTransfer.files) {
        fs.readFile(file.path, { "encoding": "UTF-8" }, (err, res) => {
          if (err) throw err;
          READ.innerHTML += `<h3>文件名称:${file.name}</h3><pre>文件的内容:<xmp>${res}</xmp></pre>`;
        });
      };
    } catch (err) {
      console.error(JSON.stringify(err));
    } finally {
      console.log(`成功了吧`);
    };
  });
  DROP.addEventListener("dragover", e => {
    e.preventDefault();
    e.stopPropagation();
  });
});